<?php $this->headScript()->appendFile($this->JS_PATH . 'dashboard.js'); ?>
<?php $this->headScript()->appendFile($this->JS_PATH . 'bootstrap.datepicker.js'); ?>

<div id="dashboard-listing"></div>
<?php echo $this->flashmessages(); ?>
<?php 
if (count($this->errorMessage) > 0): ?>
    <div class="alert alert-error">
        <?php foreach ($this->errorMessage as $erroValue): ?>
                <div class="text-left">
                    <i class="icon-remove-sign"></i>
                    <?php echo $erroValue; ?>
                </div>

        <?php endforeach; ?>
    </div>
<?php endif; ?>

<div id="pad-wrapper">
    <div class="row pagelist-header">
        <h3><?php echo $this->translate("contractor_list_dashboard"); ?></h3>
    </div>
    
    <div class="table-products">
        
        <form action="" method="post" id="contractorlistingfrm">
           
            <div class="row-fluid dashboard">
                        <div class="pull-right">
                            <div class="search_main_box">
                            
                            <div class="search_leftbox">
                            <input type="text"  placeholder="Comment"  style="width:150px;height: 20px;" class="search" name="dash_comment" id="dash_comment" value="<?php echo $this->dash_comment;?>"/>
                            &nbsp;
                            <input type="text"  placeholder="From Date"  style="width:150px;height: 20px;" class="search datepicker" name="frm_date" id="frm_date" value="<?php echo $this->frm_date;?>"/>
                            &nbsp;
                            <input type="text"  placeholder="To Date"  style="width:150px;height: 20px;" class="search datepicker" name="to_date" id="to_date" value="<?php echo $this->to_date;?>"/>
                            
                            <div class="ui-select">
                                <select name="req_reference" id="req_reference">
                                    <option value=""><?php echo $this->translate("select_ref_no"); ?></option>
                                     <?php foreach ($this->searchrequestData as $ref_key => $ref_value) : 
                                         if($this->req_ref == $ref_value['req_reference']):
                                             $selected = "selected";
                                         else:
                                             $selected = "";
                                         endif;
                                     ?>
                                    <option <?php echo $selected;?> value="<?php echo $ref_value['req_reference']?>"><?php echo $ref_value['req_reference']?></option>
                                     <?php endforeach;?>
                                </select>
                            </div>
                            
                            <div class="ui-select">
                                <select name="site_id" id="site_id">
                                    <option value=""><?php echo $this->translate("select_site"); ?></option>
                                     <?php foreach ($this->searchrequestData as $site_key => $site_value) :
                                         if($this->site_id == $site_value['site_id']):
                                             $selected = "selected";
                                         else:
                                             $selected = "";
                                         endif;?>
                                    <option <?php echo $selected;?> value="<?php echo $site_value['site_id']?>"><?php echo $site_value['site_name']?></option>
                                     <?php endforeach;?>
                                </select>
                            </div>
                            
                            <div class="ui-select">
                                <select name="subj_id" id="subj_id">
                                    <option value=""><?php echo $this->translate("select_subject"); ?></option>
                                    <?php foreach ($this->searchrequestData as $subj_key => $subj_value) : 
                                        if($this->subj_id == $subj_value['subj_id']):
                                             $selected = "selected";
                                         else:
                                             $selected = "";
                                         endif;
                                        ?>
                                    <option <?php echo $selected;?> value="<?php echo $subj_value['subj_id']?>"><?php echo $subj_value['subj_name']?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                            
                            <div class="ui-select">
                                <select name="ass_status" id="ass_status">
                                    <option value=""><?php echo $this->translate("select_Status"); ?></option>
                                    <?php foreach ($this->assignstatus as $status_key => $status_value) : 
                                        if($this->ass_status == $status_key):
                                             $selected = "selected";
                                         else:
                                             $selected = "";
                                         endif;?>
                                    <option <?php echo $selected;?> value="<?php echo $status_key;?>"><?php echo $status_value;?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                            
                            </div>
                            <div class="search_rightbox">
                            <input type="submit" value="<?php echo $this->translate("search_field"); ?>" name="searchbutton"  id="searchbutton" class="btn-flat new-product"/>      
                            <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'downloadpdf'), 'default', false); ?>" class="btn-flat new-product"><?php echo $this->translate("download_pdf"); ?></a>
                            </div>
                                </div>
                        </div>
           </div>
            <br/>
            <div class="row ">
                <?php if (count($this->requestData) > 0): ?> 
                <div class="delete_All display-none">    
                    <input type="submit" accesskey="s" value="<?php echo $this->translate("delete_all"); ?>" name="multiaction"  id="multiaction" class="btn-flat danger"/>      
                   <?php else: ?>
                        &nbsp;
                <?php endif; ?>
                </div> 
          
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th class="col-md-3 ">
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_date', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_only_date"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_date', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            <th class="col-md-3 ">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_reference', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_ref"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_reference', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>

                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'site_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_site"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'site_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'subj_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_subject"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'subj_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_comment', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_comment"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_comment', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'com_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_who"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'com_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'contractor', 'action' => 'dashboard', 'field' => 'cont_firstname', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                <?php echo $this->translate("contractor_dash_assigned"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'contractor', 'action' => 'dashboard', 'field' => 'cont_firstname', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            

                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_status', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                               <?php echo $this->translate("contractor_list_status"); ?>
                                <a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'dashboard', 'field' => 'req_status', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            <th></th>
                            
                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (count($this->requestData) > 0): ?>
                            <?php $counter = 0; ?>
                            <?php foreach ($this->requestData as $key => $value) : ?>
                                <!-- row -->
                                <tr <?php if ($counter == 0): ?>class="first"<?php endif; ?>>
                                    <td>
                                        <?php echo $value['req_date'];?>
                                    </td>
                                    <td >
                                        <?php echo $value['req_reference']; ?>
                                    </td>

                                    <td>
                                        <?php echo ucfirst($value['site_name']); ?>
                                    </td>
                                    
                                    <td>
                                        <?php echo ucfirst($value['subj_name']); ?>
                                    </td>
                                    
                                    <td>
                                        <?php echo ucfirst($value['req_comment']); ?>
                                        <br/>
                                        <?php if($value["req_closerequest"] == 1): ?>
                                        <b>Request is been closed and resolution time is : </b>
                                        <?php
                                            $start_date = date('Y-m-d H:i:s',  strtotime($value['req_createddate']));
                                            $end_date = date('Y-m-d H:i:s',  strtotime($value['closed_datetime']));
                                            //$start_date = new DateTime($value['req_createddate']);
                                            //$since_start = $start_date->diff($value['closed_datetime']);
                                            $start_date = new DateTime($start_date);
                                            $since_start = $start_date->diff(new DateTime($end_date));

                                            $minutes = $since_start->days * 24 * 60;
                                            $minutes += $since_start->h * 60;
                                            $minutes += $since_start->i;
                                            echo $minutes.' Minutes';
                                            ?>
                                        <?php endif;?>
                                    </td>
                                    
                                    <td>
                                        <?php 
                                        if($value['cust_name']!=''){
                                            echo ucfirst($value['cust_name']);
                                        }if($value['cont_name']!=''){
                                            echo ucfirst($value['cont_name']);
                                        }if($value['adm_name']!=''){
                                            echo ucfirst($value['adm_name']);
                                        }
                                        echo " (";
                                        echo ucfirst($value['com_name']);
                                        echo " )";?>
                                    </td>
                                    <td>
                                        <?php 
                                       if($value['cont_firstname']!= ''){
                                                echo ucfirst($value['cont_firstname']." ".$value['cont_lastname']);
                                                echo ' (Contractor)';
                                            }else if($value['cust_firstname']!= ''){
                                                echo ucfirst($value['cust_firstname']." ".$value['cust_lastname']);
                                                echo ' (Customer)';
                                            } else{?>
                                            <span class="label label-default">Pending</span>
                                            <?php }
                                        ?>
                                    </td>
                                    <td>
                                        <?php if ($value['ass_status'] == 3): ?>
                                            <span class="label label-success">Done</span>
                                        <?php endif;?>
                                        <?php if ($value['ass_status'] == 4): ?>
                                            <span class="label label-default">Pending</span>
                                        <?php endif;?>
                                        <?php if ($value['ass_status'] == 5): ?>
                                            <span class="label label-add">In Progress</span>
                                        <?php endif;?>
                                        <?php if ($value['ass_status'] == 6): ?>
                                            <span class="label label-important">Assign</span>
                                        <?php endif;?>
                                        <?php if ($value['ass_status'] == 7): ?>
                                            <span class="label label-add">Seen</span>
                                        <?php endif;?>
                                        <a href="<?php echo $this->url(array('controller' => 'request', 'action' => 'comment', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <span class="label label-add">
                                                <?php echo $this->translate("dash_comment"); ?>
                                            </span> 
                                        </a>
                                           <a class="dash_comment_div"   req_id="<?php echo $value["req_id"];?>" id="dash_comment_div_<?php echo $value["req_id"];?>" href="javascript:void(0)" data-toggle ="modal">
                                            <span class="label label-add">
                                               <?php echo $this->translate("dash_view_comment"); ?>
                                            </span> 
                                        </a>   
                                            
                                        <a href="<?php echo $this->url(array('controller' => 'contractor', 'action' => 'assignrequest', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <span class="label label-add">
                                               <?php echo $this->translate("dash_assign"); ?>
                                            </span> 
                                        </a>
                                        
                                    </td>
                                    <td>

                                        
                                        <?php if($value["req_acknowledge"] == 0): ?>
                                            <a title="Acknowledge Request" href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'acknowledge', 'req_id' => $value["req_id"]), null, true); ?>">
                                                <i class="icon-ok-sign"></i>
                                            </a>
                                        <?php endif;?>
                                        <?php if($value["req_closerequest"] == 0): ?>
                                        <a title="Close Request" href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'closerequest', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <i class="icon-remove-sign"></i>
                                        </a>
                                        <?php endif;?>
                                        <a title="Delete Request" href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'deleterequest', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <i class="icon-remove"></i>
                                        </a>

                                        <a title="Attachment" href="<?php echo $this->url(array('controller' => 'request', 'action' => 'comment', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <i class="icon-book"></i>
                                        </a>
                                        <a title="Comments" href="<?php echo $this->url(array('controller' => 'request', 'action' => 'comment', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <i class="icon-comments"></i>
                                        </a>
                                        <a title="Edit" href="<?php echo $this->url(array('controller' => 'request', 'action' => 'form', 'req_id' => $value["req_id"]), null, true); ?>">
                                            <i class="icon-edit"></i>
                                        </a>
                                        
                                    </td>
                                </tr>
                                <?php $counter++; ?>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <tr class="row2" >
                                <td>&nbsp;</td>
                                <td colspan="8"> <?php echo $this->translate("no_record"); ?></td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            <?php if (count($this->requestData) > 0): 
                echo $this->paginator->displayPages();
           endif; ?>
            
        </form>
    </div>
</div>




<!--popup-->

    <div class="modal fade" id="dash_comment_div_resp" tabindex="-1" role="dialog">
        <div id="contractorcompany-listing"></div>
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title"><?php echo $this->translate("view_comment_popup"); ?> </h4>
            
            </div>
              <div class="modal-body" id="modalContent">
               </div>
              <div class="modal-footer">
              <button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
            </div>
            
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
  </div>
